<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
        "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <title>写题解</title>
    <script type='text/javascript' src='js/jquery.min.js'></script>
    <meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
    <script type="text/javascript" charset="utf-8" src="utf8-jsp/ueditor.config.js"></script>
    <script type="text/javascript" charset="utf-8" src="utf8-jsp/ueditor.all.min.js"> </script>
    <script type="text/javascript" charset="utf-8" src="utf8-jsp/lang/zh-cn/zh-cn.js"></script>
    <script>location.assign("md-editor/editor.md-master/examples/simple.html");</script>
    <!-- Add Bootstrap CSS -->
    <link rel="stylesheet" href="css/bootstrap.css">
    <style type="text/css">
        body {
            background-color: #36454f;
            color: white;
        }
        .dropbtn {
            background-color: transparent;
            color: white;
            padding-left: 35px;
            padding-right: 35px;
            font-size: 16px;
            border: none;
            cursor: pointer;
        }
        .dropdown {
            margin-left: 10px;
            position: relative;
            display: inline-block;text-align: center;
        }
        .dropdown-content {
            display: none;
            position: absolute;
            background-color: #f9f9f9;
            width: 100%;;
            box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
        }
        .dropdown-content a {
            color: black;
            padding: 12px 16px;
            text-decoration: none;
            display: block;
        }
        .dropdown-content a:hover {
            background-color: #f1f1f1
        }
        .dropdown:hover .dropdown-content {
            display: block;
        }
        .dropdown:hover .dropbtn {
            background-color: transparent;
        }
        .navbar {
            margin: 0;
            padding: 0;
            background-color: #222;
        }
        #daohang {
            display: inline-block;
            list-style-type: none;
            margin: 0;
            padding: 0;
            overflow: hidden;
            background-color: transparent;
        }
        li {
            float: left;
        }
        li a {
            display: inline-block;
            color: white;
            text-align: center;
            padding: 14px 16px;
            text-decoration: none;
        }
        li a:hover {
            background-color: #111;
        }

        /* Add editor container style */
        .editor-container {
            width: 1024px;
            margin: 20px auto;
            padding: 20px;
            background-color: #fff;
            box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
            border-radius: 4px;
        }

    </style>
</head>
<body bgcolor="#36454f">
<nav class="navbar navbar-expand-md navbar-dark fixed-top sticky-navigation">
    <ul id="daohang">
        <li>
            <div style="margin-top: 10px;margin-bottom: 5px;display: inline-block;font-size: 20px" id="name" align="right
        ">
                <a style="color: white" href="aboutUs.html"><strong>别叫我OJ</strong></a>
            </div>
        </li>
        <li>
            <div style="margin-left:20px;margin-top: 10px;margin-bottom: 5px;display: inline-block" id="index" align="right">
                <a style="color: white" href="index.html">首页</a>
            </div>
        </li>
        <li>
            <div style="margin-left:20px;margin-top: 10px;margin-bottom: 5px;display: inline-block" id="userDetail" align="right">
                <a style="color: white" href="userDetail.html">个人中心</a>
            </div>
        </li>
    </ul>
    <div style="display: inline-block;float: right" class="collapse navbar-collapse" id="topMenu">
        <ul class="navbar-nav ml-auto" >
            <div style="margin:5px;display: inline-block" id="javaoj">
                <a style="color: white" href="login.html" onclick="logout()"> 退出登录</a>
                <div class="dropdown">
                    <button class="dropbtn">设置</button>
                    <div class="dropdown-content">
                        <a href="updateInfo.html">修改个人信息</a>
                        <a href="updatePassword.html">修改密码</a>
                    </div>
                </div>
            </div>
        </ul>
    </div>
</nav>
<div>
    <h2 style="color: white" id="problemTitle">题目名称</h2><!-- Add editor container -->
    <div class="editor-container">
        <script id="editor" type="text/plain" style="width:100%;height:500px;"></script>
    </div>
</div>
<div id="btns" class="text-center my-4">
    <button class="btn btn-primary" onclick="addAnswer()">提交题解</button>
   <!-- <button class="btn btn-secondary" onclick="getPlainTxt()">获得带格式的纯文本</button>
    <button class="btn btn-info" onclick="hasContent()">判断是否有内容</button>
    <button class="btn btn-warning" onclick="setFocus()">使编辑器获得焦点</button>-->
    <button class="btn btn-danger" onmousedown="isFocus(event)">新页面</button>
    <!--<button class="btn btn-dark" onmousedown="setblur(event)">编辑器失去焦点</button>
    <button class="btn btn-success" onclick="getText()">获得当前选中的文本</button>
    <button class="btn btn-primary" onclick="insertHtml()">插入给定的内容</button>-->
</div>
<!-- Add Bootstrap JS -->
<!--<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script>-->
<!--<script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.9.3/dist/umd/popper.min.js"></script>-->
<!--<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>-->
<script type="text/javascript">
    //location.assign()
    function getQueryParameter(parameterName) {
        const urlParams = new URLSearchParams(window.location.search);
        return urlParams.get(parameterName);
    }
    /*获取用户id和password*/
    var userId=localStorage.getItem("userId");
    var password=localStorage.getItem("password");
    //获取用户登录信息，获取失败则返回登录页面
    function getUser(){
        if (userId==null){
            location.assign("login.html");
        }
    }
    function logout(){
        localStorage.clear();
    }
    getUser();

    // 使用函数获取id参数
    const id = localStorage.getItem("questionId");
    console.log("ID:", id);

    let problemTitle = document.getElementById("problemTitle");

    //实例化编辑器
    var ue = UE.getEditor('editor');

    //提交题解
    function addAnswer() {
        // 获取编辑器的内容
        var content = ue.getContent();
        console.log(content);
        let answer={
            userId:userId,
            questionId:id,
            content:content,
        };
        console.log(answer);
        // var answerJson = JSON.stringify(answer);
        // var obj = JSON.parse(answer.inputList);
        //console.log(obj);
        if(content!=null){
            $.ajax({
                url:"http://192.168.47.129:8010/user/publishAnswer",
                type:"POST",
                contentType:"application/json; charset=utf-8",
                data:JSON.stringify(answer),
                success:function(data){
                    location.assign("answer.html");
                }
            })
        }
    }


    //编辑器是否获得焦点
    function isFocus(event) {
        location.assign("md-editor/editor.md-master/examples/simple.html");
    }
    // 设置题目名称
    function setProblemTitle(title) {
        problemTitle.innerText = title;
    }
    // 示例：设置题目名称
    /*setProblemTitle("示例题目：两数之和");*/
</script>
</body>
</html>





